package com.qlk.odcinterface.service.impl;

import java.util.List;

import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.qlk.odcinterface.domain.PmsCouponChannel;
import com.qlk.odcinterface.domain.query.PmsCouponChannelQuery;
import com.qlk.odcinterface.manager.PmsCouponChannelManager;
import com.qlk.odcinterface.service.PmsCouponChannelService;
import com.qlk.odcinterface.utils.exceptions.ExistedException;
import com.qlk.common.utils.page.PageUtil;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.perf4j.aop.Profiled;
 
/**
 * PmsCouponChannelService接口的实现类
 * 
 * @author zhaoyanan
 * @version 2016-4-14 14:11:36
 * 
 */
@Service
public class PmsCouponChannelServiceImpl implements PmsCouponChannelService {

    /** LOG */
    private static final Log LOG = LogFactory.getLog(PmsCouponChannelServiceImpl.class);

    @Autowired
    private PmsCouponChannelManager pmsCouponChannelManager;

    /**
     * {@inheritDoc}
     */
    @Profiled(tag = "PmsCouponChannelService.batchInsert")
    public boolean insert(List<PmsCouponChannel> pmsCouponChannelList) {
        boolean resultFlag = false;
        try {
            if (CollectionUtils.isNotEmpty(pmsCouponChannelList)) {
                resultFlag = pmsCouponChannelManager.insert(pmsCouponChannelList);
            } else {
                LOG.warn("PmsCouponChannelServiceImpl#batchInsert failed, param is illegal.");
            }
        } catch (Exception e) {
            LOG.error("PmsCouponChannelServiceImpl#batchInsert has error.", e);
        }
        return resultFlag;
    }

    /**
     * {@inheritDoc}
     */
    @Profiled(tag = "PmsCouponChannelService.insert")
    public boolean insert(PmsCouponChannel pmsCouponChannel) {
        boolean resultFlag = false;
        try {
            if (null != pmsCouponChannel) {
                if (pmsCouponChannelManager.exist(pmsCouponChannel)) {
                    throw new ExistedException();
                }
                resultFlag = pmsCouponChannelManager.insert(pmsCouponChannel);
            } else {
                LOG.warn("PmsCouponChannelServiceImpl#insert failed, param is illegal.");
            }
        } catch (ExistedException e) {
            LOG.warn("PmsCouponChannelServiceImpl#insert failed, pmsCouponChannel has existed.");
            throw e;
        } catch (Exception e) {
            LOG.error("PmsCouponChannelServiceImpl#insert has error.", e);
        }
        return resultFlag;
    }

    /**
     * {@inheritDoc}
     */
    @Profiled(tag = "PmsCouponChannelService.update")
    public boolean update(PmsCouponChannel pmsCouponChannel) {
        boolean resultFlag = false;
        try {
            if (null != pmsCouponChannel && null != pmsCouponChannel.getId()) {
                resultFlag = pmsCouponChannelManager.update(pmsCouponChannel);
            } else {
                LOG.warn("PmsCouponChannelServiceImpl#update failed, param is illegal.");
            }
        } catch (Exception e) {
            LOG.error("PmsCouponChannelServiceImpl#update has error.", e);
        }
        return resultFlag;
    }

    /**
     * {@inheritDoc}
     */
    @Profiled(tag = "PmsCouponChannelService.queryPmsCouponChannelList")
    public List<PmsCouponChannel> queryPmsCouponChannelList(PmsCouponChannelQuery queryBean) {
        List<PmsCouponChannel> pmsCouponChannelList = null;
        try {
            pmsCouponChannelList = pmsCouponChannelManager.queryPmsCouponChannelList(queryBean);
        } catch (Exception e) {
            LOG.error("PmsCouponChannelServiceImpl#queryPmsCouponChannelList has error.", e);
        }
        return pmsCouponChannelList;
    }

    /**
     * {@inheritDoc}
     */
    @Profiled(tag = "PmsCouponChannelService.queryPmsCouponChannelListWithPage")
    public List<PmsCouponChannel> queryPmsCouponChannelListWithPage(PmsCouponChannelQuery queryBean, PageUtil pageUtil) {
        List<PmsCouponChannel> pmsCouponChannelList = null;
        try {
            pmsCouponChannelList = pmsCouponChannelManager.queryPmsCouponChannelListWithPage(queryBean, pageUtil);
        } catch (Exception e) {
            LOG.error("PmsCouponChannelServiceImpl#queryPmsCouponChannelListWithPage has error.", e);
        }
        return pmsCouponChannelList;
    }

    /**
     * {@inheritDoc}
     */
    @Profiled(tag = "PmsCouponChannelService.delete")
    public boolean delete(PmsCouponChannel pmsCouponChannel) {
        boolean resultFlag = false;
        try {
            if (null != pmsCouponChannel && null != pmsCouponChannel.getId()) {
                resultFlag = pmsCouponChannelManager.delete(pmsCouponChannel);
            } else {
                LOG.warn("PmsCouponChannelServiceImpl#delete param is illegal.");
            }
        } catch (Exception e) {
            LOG.error("PmsCouponChannelServiceImpl#delete has error.", e);
        }
        return resultFlag;
    }

    /**
     * {@inheritDoc}
     */
    @Profiled(tag = "PmsCouponChannelService.batchDelete")
    public boolean delete(PmsCouponChannel[] pmsCouponChannels) {
        boolean resultFlag = false;
        try {
            if (null != pmsCouponChannels && pmsCouponChannels.length > 0) {
                resultFlag = pmsCouponChannelManager.delete(pmsCouponChannels);
            } else {
                LOG.warn("PmsCouponChannelServiceImpl#batchDelete failed, param is illegal.");
            }
        } catch (Exception e) {
            LOG.error("PmsCouponChannelServiceImpl#batchDelete has error.", e);
        }
        return resultFlag;
    }

    /**
     * {@inheritDoc}
     */
    @Profiled(tag = "PmsCouponChannelService.getPmsCouponChannelById")
    public PmsCouponChannel getPmsCouponChannelById(Integer id) {
        PmsCouponChannel pmsCouponChannel = null;
        try {
            if (null != id) {
                pmsCouponChannel = pmsCouponChannelManager.getPmsCouponChannelById(id);
            } else {
                LOG.warn("PmsCouponChannelServiceImpl#getPmsCouponChannelById failed, param is illegal.");
            }
        } catch (Exception e) {
            LOG.error("PmsCouponChannelServiceImpl#getPmsCouponChannelById has error.", e);
        }
        return pmsCouponChannel;
    }
}

